<?php
use \Entities;
use Engine\Auth\CurrentUser as USER;
use \Managers;

class WarcraftController extends Zend_Controller_Action
{

    public function init() {
        
    }
    
    public function indexAction() {
        
//        show($_POST);
        
      //  $this->_helper->layout->disableLayout();
        
        if (!$userId = USER::getId()) {          
            
            setcookie('backUrl',$_SERVER["REQUEST_URI"]);
            $this->_redirect($this->view->url(array(), 'login'));  
            
            } else {
            
            $warcraft = new \Managers\Warcraft();
            if($maps = $this->_getParam('maps')){
//                $selMaps = $warcraft->getSelectedMaps($maps);
                
                if(count($selMaps)){
                    $warcraft->saveMaps($userId, $maps);
                }
            }
//            die("A");
                
            
            
            
            
            $data = $warcraft->getData($userId);

            if($data) { 
                $maps = $warcraft->getMaps($userId, unserialize($data->getMaps())); 
                $allmaps = $warcraft->getAllMaps();
                $warcraftForm = new Form_Warcraft($data, $maps, $allmaps);
            } else {
                $warcraftForm = new Form_Warcraft();
            }
           
            
            $this->view->form = $warcraftForm->getForm();
            
            }
 
        }

}

